package com.block.api.controller.vest;


import com.alibaba.fastjson.JSONObject;
import com.block.common.annotate.NeedToken;
import com.block.common.bean.CommonParam;
import com.block.common.bean.SessionBean;
import com.block.common.constant.AppRspCodeConstant;
import com.block.common.exception.ApiException;
import com.block.common.security.util.ApiUtil;
import com.block.common.vo.ResponseVo;
import com.block.db.entity.AppEncrypt;
import com.block.vest.service.IBankCardInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("api/core/card")
public class BankCardInfoController {

    @Autowired
    IBankCardInfoService bankCardInfoService;

    @NeedToken
    @RequestMapping(value = "/updateInfo", method = {RequestMethod.POST, RequestMethod.GET})
    public String updateInfo(@RequestAttribute(value = "tranData") JSONObject tranData,
                                 @RequestAttribute(value = "appEncrypt") AppEncrypt appEncrypt,
                                 @RequestAttribute(value = "uri") String uri,
                                 @RequestAttribute(value = "commonParam") CommonParam commonParam,
                                 @RequestAttribute(value = "startDate") Date startdate,
                                 @RequestAttribute(value = "sessionBean") SessionBean sessionBean,
                                 @RequestAttribute(value = "ip") String ip) throws ApiException {

//        BankCardInfoDTO cardInfoDTO = JSON.parseObject(tranData.toJSONString(), BankCardInfoDTO.class);
//        cardInfoDTO.setUid(sessionBean.getUid());
        ResponseVo responseVo = new ResponseVo(AppRspCodeConstant.SUCCESS);//bankCardInfoService.updateInfo(cardInfoDTO);
        return ApiUtil.dealReturnJson(responseVo, appEncrypt, "1.0", startdate, uri);
    }

    @NeedToken
    @RequestMapping(value = "/dataList", method = {RequestMethod.POST, RequestMethod.GET})
    public String dataList(@RequestAttribute(value = "tranData") JSONObject tranData,
                               @RequestAttribute(value = "appEncrypt") AppEncrypt appEncrypt,
                               @RequestAttribute(value = "uri") String uri,
                               @RequestAttribute(value = "commonParam") CommonParam commonParam,
                               @RequestAttribute(value = "startDate") Date startdate,
                               @RequestAttribute(value = "sessionBean") SessionBean sessionBean,
                               @RequestAttribute(value = "ip") String ip) throws ApiException {

        ResponseVo responseVo = bankCardInfoService.dataList(sessionBean.getUid());
        return ApiUtil.dealReturnJson(responseVo, appEncrypt, "1.0", startdate, uri);
    }
}